package com.globallogic.dailyplanner.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.globallogic.dailyplanner.dto.History;
import com.globallogic.dailyplanner.repository.HistoryRepository;
import com.globallogic.dailyplanner.service.HistoryService;

@Service
public class HistoryServiceImpl implements HistoryService {

	@Autowired
	HistoryRepository historyRepository;
	
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	public List<History> getAllByUserId(int id) {
		return historyRepository.findById(id);
	}

	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	public List<History> getAll() {
		return historyRepository.findAll();
	}

	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	public History getById(int id) {
		return historyRepository.findOne(id);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRES_NEW, timeout=30)
	public History save(History history) {
		return historyRepository.saveAndFlush(history);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRES_NEW, timeout=30)
	public void delete(History history) {
		historyRepository.delete(history);
	}

}
